﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>layui在线调试</title>
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    @*<style>
        body {
        margin: 10px;
        }

        .demo-carousel {
        height: 200px;
        line-height: 200px;
        text-align: center;
        }

        .layui-table-tool-self {
        display: none;
        }
        </style>*@
</head>
<body>
    <div class="layui-inline">
        <label class="layui-form-label">负责人：</label>
        <div class="layui-input-inline">
            <input type="text" id="name" name="name" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <button type="submit" id="button" class="layui-btn layui-btn-primary"><i class="layui-icon"></i> 搜 索</button>
    </div>

    <table class="layui-hide" id="demo" lay-filter="test"></table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
        {{# if(d.state==0){}}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="signup">提交审批</a>
        {{# } else { }}
        <input type="button" class="layui-btn layui-btn-danger layui-btn-xs" value="已提交" disabled />
        {{# } }}
    </script>

    <script src="~/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>
    <script>
        //layui.config({
        //    version: '1606182314890' //为了更新 js 缓存，可忽略
        //});

        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer //弹层
                , table = layui.table //表格

            //执行一个 table 实例
            table.render({
                elem: '#demo'
                , url: '/CurrencyContract/GetList' //数据接口
                , title: '通用合同管理表'
                , id:'RoleTable'
                , page: true //开启分页
                , toolbar: 'default' //开启头工具栏，此处显示默认图标，可以自定义模板，详见文档
                , limit: 6
                , limits: [3, 6, 9, 12]
                , cols: [[ //表头
                    { type: 'checkbox', fixed: 'left' }//锁定第一列
                    , { field: 'id', width: 102, title: '编号', sort: true }
                    , { field: 'numberId', width: 102, title: '合同编号', sort: true }
                    , { field: 'contractTitle', width: 120, title: '合同标题' }
                    , { field: 'fName', width: 180, title: '外协单位' }
                    , { field: 'oName', width: 110, title: '外协负责人' }
                    , { field: 'lName', title: '线路名称', width: 100 }
                    , { field: 'freightrate', width: 100, title: '吨运价'}
                    , { field: 'charterConditions', width: 100, title: '包车条件吨位', sort: true }
                    , { field: 'charterAmount', width: 100, title: '包车金额' }
                    , { field: 'signingDate', title: '签订日期', width: 185,templet: "<div>{{layui.util.toDateString(d.setTime, 'yyyy-MM-dd HH:mm')}}</div>"}
                    , { field: 'handler', width: 120, title: '经办人' }
                    , {
                        field: 'state', title: '审批状态', width: 120, templet: function (d) {
                            if (d.state == 1) {
                                return "未审批";
                            } else if (d.state == 2) {
                                return "已审批";
                            }
                            else {
                                return "未提交";
                            }
                        }
                    }
                    , { fixed: 'right', width: 220, align: 'center',title: '操作', toolbar: '#barDemo' }
                ]]
            });

            //监听头工具栏事件
            table.on('toolbar', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id)
                    , data = checkStatus.data; //获取选中的数据
                switch (obj.event) {
                    case 'add':
                        //layer.msg('添加');
                        location.href="/CurrencyContract/AddCurrency";
                        break;
                    case 'update':
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else if (data.length > 1) {
                            layer.msg('只能同时编辑一个');
                        } else {
                            location.href="/CurrencyContract/Edit?Id="+checkStatus.data[0].id;
                            //layer.alert('编辑Id：' + checkStatus.data[0].id);
                        }
                        break;
                    case 'delete':
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else {
                            //layer.alert('删除Id：' + checkStatus.data[0].Id);
                            //layer.msg('删除');
                            layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url:"/CurrencyContract/DeleteCurrencybyId?id="+checkStatus.data[0].id,
                            type:"get",
                            dataType:"json",
                            success:function(obj){
                                if(obj>0){
                                    layer.msg('删除成功');
                                }
                            }
                        })
                        obj.del(); //删除对应行（tr）的DOM结构
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                        }
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"

                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'detail') {
                    //layer.msg('查看操作');
                    layer.open({
                        type: 2,
                        title: '查看数据',
                        skin: 'layui-layer-rim', //加上边框
                        area: ['750px', '450px'], //宽高
                        content: '/CurrencyContract/Show?Id=' + data.id
                    });
                    //location.href = '/CarryContract/Show?Id=' + data.id;
                } else if (layEvent === 'delete') {
                    layer.msg(data.id);
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url:"/CurrencyContract/DeleteCurrencybyId?id="+data.id,
                            type:"get",
                            dataType:"json",
                            success:function(obj){
                                if(obj>0){
                                    layer.msg('删除成功');
                                }
                            }
                        })
                        obj.del(); //删除对应行（tr）的DOM结构
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                } else if (layEvent === 'edit') {
                    location.href="/CurrencyContract/Edit?Id="+data.id;
                    //layer.msg('编辑操作');
                } else if (layEvent === 'signup') {
                    $.ajax({
                        url: "/CurrencyContract/UP?id=" + data.id + "&TId=3",
                        type: "get",
                        dataType: "json",
                        success: function (obj) {
                            if (obj > 0) {
                                layer.msg('提交成功');
                            }
                        }
                    })
                }
            });
            $("#button").click(function () {
                var Title = $("#name").val();
                table.reload('RoleTable', {
                    url: '/CurrencyContract/GetList'
                    , where: {
                        Title: Title
                    }
                    , page: {
                        curr: 1
                    }
                });
            })
        });
    </script>
</body>
</html>

